define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'withdrawal_setting/index' + location.search,
                    add_url: 'withdrawal_setting/add',
                    edit_url: 'withdrawal_setting/edit',
                    del_url: 'withdrawal_setting/del',
                    multi_url: 'withdrawal_setting/multi',
                    import_url: 'withdrawal_setting/import',
                    table: 'withdrawal_setting',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'type.name', title: __('Type.name'), operate: 'LIKE'},
                        {field: 'clearing_form', title: __('Clearing_form')},
                        {field: 'is_open', title: __('Is_open')},
                        {field: 'withdrawal_start_time', title: __('Withdrawal_start_time'), operate: 'LIKE'},
                        {field: 'withdrawal_end_time', title: __('Withdrawal_end_time'), operate: 'LIKE'},
                        {field: 'withdrawal_min_money', title: __('Withdrawal_min_money'), operate:'BETWEEN'},
                        {field: 'withdrawal_max_money', title: __('Withdrawal_max_money'), operate:'BETWEEN'},
                        {field: 'service_charge', title: __('Service_charge'), operate:'BETWEEN'},
                        {field: 'tax_rate', title: __('Tax_rate')},
                        {field: 'withdrawal_number', title: '单日提现次数'},
                        {field: 'status', title: __('Status'), searchList: {"1":__('Status 1'),"2":__('Status 2')}, formatter: Table.api.formatter.status},
                        {field: 'create_time', title: __('Create_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);

            $(".btn-closed").click(function () {
                var ids = JSON.stringify(Table.api.selectedids(table));
                Fast.api.open('withdrawal_setting/closed?ids=' + ids, "录入", {});
            })
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        closed: function () {
            Controller.api.bindevent();
        },
        settings: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
